﻿using System;
using Lua;
using MoonSharp.Interpreter;
using UnityEngine;

// Token: 0x02000202 RID: 514
public class LuaMotive : IMotive
{
	// Token: 0x06000AED RID: 2797 RVA: 0x0005CB1C File Offset: 0x0005AD1C
	public LuaMotive(Table t, Script s)
	{
		this.script = s;
		this.table = t;
		foreach (TablePair tablePair in this.table.Pairs)
		{
			if (tablePair.Key.Type == DataType.String)
			{
				string @string = tablePair.Key.String;
				if (@string == "name")
				{
					this.internalName = tablePair.Value.String;
				}
				else if (@string == "data")
				{
					this.ParseData(tablePair.Value.Table);
				}
			}
		}
		this.functionCreateInstance = this.script.Globals.Get("CreateMotiveInstance");
	}

	// Token: 0x06000AEE RID: 2798 RVA: 0x00002973 File Offset: 0x00000B73
	private void ParseData(Table data)
	{
	}

	// Token: 0x06000AEF RID: 2799 RVA: 0x0005CC1C File Offset: 0x0005AE1C
	public IMotiveInstance CreateInstance(EntityBase agent)
	{
		LuaMotiveInstance luaMotiveInstance = null;
		Entity luaEntity = agent.GetLuaEntity();
		try
		{
			DynValue dynValue = this.script.Call(this.functionCreateInstance, new object[]
			{
				this.internalName,
				luaEntity
			});
			luaMotiveInstance = new LuaMotiveInstance(dynValue.Table, this.script);
			luaMotiveInstance.behaviorFilename = this.filename;
		}
		catch (ScriptRuntimeException ex)
		{
			Debug.LogError(ex.DecoratedMessage);
		}
		return luaMotiveInstance;
	}

	// Token: 0x06000AF0 RID: 2800 RVA: 0x0005CC9C File Offset: 0x0005AE9C
	public string GetName()
	{
		return this.internalName;
	}

	// Token: 0x04001002 RID: 4098
	public string filename = string.Empty;

	// Token: 0x04001003 RID: 4099
	private string internalName;

	// Token: 0x04001004 RID: 4100
	public Script script;

	// Token: 0x04001005 RID: 4101
	private Table table;

	// Token: 0x04001006 RID: 4102
	private DynValue functionCreateInstance;
}
